package client;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Font;

import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.JButton;

import server.BkWatITF;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import client.Configuration;

public class BkStaffRegisterGUI extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JPasswordField passwordField_1;

	/**
	 * Launch the application.
	 */
	
	Configuration config=new Configuration();
	String rmiAddress=config.getRmiAddress();
	BkWatITF Witf;
    Person ps = new Person();
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					BkStaffRegisterGUI frame = new BkStaffRegisterGUI();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public BkStaffRegisterGUI() {
		setTitle("\u6C42\u804C\u767B\u8BB0\u8868");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel label = new JLabel("\u8BF7\u586B\u5199\u60A8\u7684\u6709\u6548\u4FE1\u606F\uFF1A");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		label.setBounds(47, 20, 221, 27);
		contentPane.add(label);
		
		JLabel label_1 = new JLabel("\u59D3\u540D\uFF1A");
		label_1.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		label_1.setBounds(94, 74, 84, 21);
		contentPane.add(label_1);
		
		textField = new JTextField();
		textField.setColumns(10);
		textField.setBounds(188, 72, 153, 27);
		contentPane.add(textField);
		
		JLabel label_3 = new JLabel("\u767B\u5F55\u5BC6\u7801\uFF1A");
		label_3.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		label_3.setBounds(94, 122, 95, 21);
		contentPane.add(label_3);
		
		passwordField_1 = new JPasswordField();
		passwordField_1.setBounds(188, 120, 153, 27);
		contentPane.add(passwordField_1);
		
		JButton button = new JButton("\u786E\u8BA4\u767B\u8BB0");
		button.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				try {
					Witf = (BkWatITF) Naming.lookup(rmiAddress+"BankWanter");
					String name = textField.getText();
				String skey = passwordField_1.getText();
				
				if(skey.equals("")||name.equals(""))
					JOptionPane.showMessageDialog(null, "输入不能为空！");
				else{
					int pID = ps.getPID();
					int pkey = Integer.parseInt(skey);
					if(!Witf.addWanter(pID, name, pkey)){
						JOptionPane.showMessageDialog(null, "您已经登记过！");
					}else{
						JOptionPane.showMessageDialog(null, "已登记，感谢参与！有聘用信息我们会及时与您联络。");
					}
					
					dispose();
					HomePageGUI frame = new HomePageGUI();
					frame.setLocationRelativeTo(null);
					frame.setVisible(true);
				}
				} catch (MalformedURLException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (RemoteException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				} catch (NotBoundException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
			    
		}});
		button.setFont(new Font("微软雅黑", Font.PLAIN, 17));
		button.setBounds(277, 194, 109, 45);
		contentPane.add(button);
		}

	}
	
